<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./OL_SDK/include-openlayers-local.js"></script>
    <script src="./libs/gaode.js"></script>
</head>

<body>
    <button onclick="addLine()">添加线</button>
    <div id="map">
    </div>
    <script>
        var docLayer = new Zondy.Map.Doc("", "myTestMap", {

        })
        var map = new ol.Map({
            target: "map",
            layers: [gaode, docLayer],
            view: new ol.View({
                projection: 'EPSG:4326',
                center: [114.30, 30.50],
                zoom: 4
            })
        })
        /* 项目组  【高工/组长】 */
        /*1、创建中地的要素*/
        /*2、创建要素集添加要素 */
        /* 3、调用服务,实现添加 */
        function addLine() {
            /* 1、要素 */
            /* 1-1、geometry */
            var pointObj = new Array();
            pointObj[0] = new Zondy.Object.Point2D(114, 30);
            pointObj[1] = new Zondy.Object.Point2D(118, 30);
            //构成折线的弧段
            var gArc = new Zondy.Object.Arc(pointObj);

            /* var pointObj1 = new Array();
            pointObj1[0] = new Zondy.Object.Point2D(110, 20);
            pointObj1[1] = new Zondy.Object.Point2D(116, 25);
            //构成折线的弧段
            var gArc1 = new Zondy.Object.Arc(pointObj1); */

            //构成线的折线
            var gAnyLine = new Zondy.Object.AnyLine([gArc]);
            //设置线要素的几何信息
            var gline = new Zondy.Object.GLine(gAnyLine);
            //设置要素的几何信息
            var fGeom = new Zondy.Object.FeatureGeometry({ LinGeom: [gline] });
            /* 1-2、style  webGraphic */
            //设置添加线要素的图形参数信息
            var clineInfo = new Zondy.Object.CLineInfo({
                "Color": 1,//线的颜色
                "LinStyleID": 0, //线型号
                "LinStyleID2": 18,//线型号
                "LinWidth": 0.05, //线宽
                "Xscale": 10,
                "Yscale": 10
            });
            //设置要素的图形参数信息
            var graphicInfo = new Zondy.Object.WebGraphicsInfo({
                InfoType: 2,
                LinInfo: clineInfo
            });
            /* 1-3、属性 */
            var attValue = ['北京哈尔滨线' + Date.now()];
            //创建一个线要素
            var newFeature = new Zondy.Object.Feature({
                fGeom: fGeom, // 几何
                GraphicInfo: graphicInfo,// 图形参数信息
                AttValue: attValue// 字段属性值组成的数组
            });
            //设置要素为线要素
            newFeature.setFType(2);
            /* 2、构建要素 --和数据库中图层映射 */
            var featureSet = new Zondy.Object.FeatureSet();
            var fldNumber = 1; //属性（字段）个数
            var fldName = ["铁路名称"];
            var fldType = ["string"];
            //创建属性结构设置对象
            var cAttStruct = new Zondy.Object.CAttStruct({
                FldName: fldName,
                FldNumber: fldNumber,
                FldType: fldType
            });
            //设置要素数据集的属性结构
            featureSet.AttStruct = cAttStruct;
            //将添加的线要素添加到属性数据集中
            featureSet.addFeature(newFeature);
            /* 3、调服务 */
            //创建一个地图编辑对象
            var editDocFeature = new Zondy.Service.EditDocFeature("myTestMap", 2, {

            });
            //执行添加线要素功能
            editDocFeature.add(featureSet, onLineSuccess);
        }
        function onLineSuccess(data) {
            console.log(data,'data')// {succeed: true}
            if (data.succeed) {
                alert("添加要素成功！");
                docLayer.refresh();
            } else {
                alert("添加要素失败！");
            }
        }
    </script>
</body>

</html>